package cn.stylefeng.guns.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.system.entity.ZApplication;
import cn.stylefeng.guns.modular.system.mapper.ZApplicationMapper;
import cn.stylefeng.guns.modular.system.model.params.ZApplicationParam;
import cn.stylefeng.guns.modular.system.model.result.ZApplicationResult;
import  cn.stylefeng.guns.modular.system.service.ZApplicationService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  装修申请
 * </p>
 *
 * @author yl
 * @since 2019-07-09
 */
@Service
public class ZApplicationServiceImpl extends ServiceImpl<ZApplicationMapper, ZApplication> implements ZApplicationService {


    @Autowired
    private ZApplicationMapper zApplicationMapper;


    @Override
    public void add(ZApplicationParam param){
        ZApplication entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(ZApplicationParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(ZApplicationParam param){
        ZApplication oldEntity = getOldEntity(param);
        ZApplication newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public ZApplicationResult findBySpec(ZApplicationParam param){
        return null;
    }

    @Override
    public List<ZApplicationResult> findListBySpec(ZApplicationParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(ZApplicationParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(ZApplicationParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private ZApplication getOldEntity(ZApplicationParam param) {
        return this.getById(getKey(param));
    }

    private ZApplication getEntity(ZApplicationParam param) {
        ZApplication entity = new ZApplication();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }


    /**
     * 查询集合
     */
    public List<ZApplication> QueryList(String condition) {
        return zApplicationMapper.QueryList(condition);
    }



    /**
     * 根据id查询数据
     */
    public List<ZApplicationResult> QueryZApplicationID(@Param("id") Long id){
        return zApplicationMapper.QueryZApplicationID(id);
    }








}
